package titt.util;

public class JAR {

	private static final JAR j = new JAR(); 
	
	public static JAR get() {
		return j;
	}
	
	private JAR() {}
	
	private boolean nameSet = false;
	private String name;
	
	public boolean isJAR() {
		return getRunningJarName() != null;
	}
	
	public synchronized String getRunningJarName() {
		if(nameSet) return name;
		
		nameSet = true;

		String className = JAR.class.getName().replace('.', '/');
		String classJar =  JAR.class.getResource("/" + className + ".class").toString();
		if (classJar.startsWith("jar:")) {
			String vals[] = classJar.split("/");
			for (String val: vals)
				if (val.contains("!"))
					return name = val.substring(0, val.length() - 1);
		}
		
		return name;
	}

	
}
